library(tidyverse)
library(maps)
library(mapdata)
library(lubridate)
library(viridis)
library(RColorBrewer)
library(plotly)
grey_theme <- theme(axis.text.x = element_text(colour="grey20", size = 12,
angle = 90, hjust = 0.5,
vjust = 0.5),
axis.text.y = element_text(colour = "grey20", size = 12),
text=element_text(size = 16))
Exercise 1:
daily_report <- read_csv(url("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_daily_reports/09-26-2020.csv")) %>%
rename(Long = "Long_")
ggplot(daily_report, aes(x = Long, y = Lat, size = Confirmed/10000)) +
borders("world", colour = NA, fill = "grey90") +
theme_bw() +
geom_point(shape = 21, color='darkmagenta', fill='darkorchid', alpha = 0.5) +
labs(title = 'World COVID-19 Confirmed cases',x = '', y = '',
size="Cases (x10,000)") +
grey_theme +
theme(legend.position = "right") +
coord_fixed(ratio=1.5)
Exercise 2:
summary(daily_report$Confirmed) #Get summary stats for new case totals
mybreaks <- c(1, 1000, 10000, 100000, 200000) #Set new breaks
ggplot(daily_report, aes(x = Long, y = Lat, size = Confirmed)) +
borders("state", colour = "grey50", fill = "grey90") + #made state borders darker
geom_point(aes(x=Long, y=Lat, size=Confirmed, color=Confirmed),stroke=F, alpha=0.7) +
scale_size_continuous(name="Cases", range=c(1,20), #removed log trans and increased point range
breaks=mybreaks, labels = c("1-999",
"1,000-9,999", "10,000-99,999",
"100,000-199,999", "200,000+")) +
scale_color_viridis_c(option="viridis", name="Cases",
breaks=mybreaks, trans="log", #kept log trans for color scale as it did a better job visually
labels = c("1-999", "1,000-9,999", "10,000-99,999",
"100,000-199,999", "200,000+")) +
#Cleaning up the graph
theme_void() +
guides( color = guide_legend()) +
labs(title = "Modified Anisa Dhana's layout for COVID-19 Confirmed Cases in the US") +
theme(
legend.position = "bottom",
text = element_text(color = "#22211d"),
plot.background = element_rect(fill = "#ffffff", color = NA),
panel.background = element_rect(fill = "#ffffff", color = NA),
legend.background = element_rect(fill = "#ffffff", color = NA)
) +
coord_fixed(ratio=1.5)
Exercise 3: I updated the cases by county color scale
ggplot(data = us, mapping = aes(x = long, y = lat, group = group)) +
coord_fixed(1.3) +
# Add data layer
borders("state", colour = "black") +
geom_polygon(data = state_join, aes(fill = Confirmed)) +
scale_fill_viridis(option = "B", trans = "log10", na.value = "lightgrey",
name = "Confirmed \ncases") +
labs(title = "Number of Confirmed Cases by US County",
x = "Longitude",
y = "Latitude") +
theme_bw()
Exercise 4: I changed the state to Connecticut (home state) and the color scale to the viridis::plasma
daily_report <- read_csv(url("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_daily_reports/09-26-2020.csv")) %>%
rename(Long = "Long_") %>%
filter(Province_State == "Connecticut") %>%
group_by(Admin2) %>%
summarize(Confirmed = sum(Confirmed)) %>%
mutate(Admin2 = tolower(Admin2)) %>%
filter(!Admin2=="unassigned") %>% #remove unassigned cases
rename(Cases = Confirmed) #renaming confirmed cases column for better plotly
us <- map_data("state")
ct_us <- subset(us, region == "connecticut")
counties <- map_data("county")
ct_county <- subset(counties, region == "connecticut")
state_join <- left_join(ct_county, daily_report, by = c("subregion" = "Admin2"))
library(plotly)
ggplotly(
ggplot(data = ct_county, mapping = aes(x = long, y = lat, group = group)) +
coord_fixed(1.3) +
# Add data layer
geom_polygon(data = state_join, aes(fill = Cases), color = "grey40") +
scale_fill_viridis(option = "plasma",
name = "Cases") +
ggtitle("COVID-19 Cases in CT") +
# Cleaning up the graph
labs(x=NULL, y=NULL) +
theme(panel.border = element_blank()) +
theme(panel.background = element_blank()) +
theme(axis.ticks = element_blank()) +
theme(axis.text = element_blank())
)